package com.meshnetics.gb.stack.core.apl.type;

/**
 * Application profile identifier.
 * It has the same allowed range as ClusterId.
 *
 * @author mmarkov
 */
public class ProfileId extends ClusterId {
    public static final ProfileId ZDP_PROFILE = new ProfileId(0);

    /**
     * Constructs ProfileId from the given int value.
     *
     * @param id int profile id
     * @throws IllegalArgumentException if the given id is < 0 or > 65535
     */
    public ProfileId(int id) {
        super(TypeProfileId.TYPE, new byte[] { (byte) (id >> 8), (byte) id });

        if ((id < MIN_ID) || (id > MAX_ID)) {
            throw new IllegalArgumentException("Invalid profile id: " + id);
        }
    }

    /**
     * Constructs ProfileId from the array of bytes (which should contain 2 elements).
     * It's needed for its constructing from TypeProfileId.createValue() method.
     *
     * @param type TypeProfileId
     * @param value byte array with 2 elements
     */
    protected ProfileId(TypeProfileId type, byte[] value) {
        super(type, value);
    }
}
